/**
@author		Jong Min, Lee
@date		  01/15/2014
@breif		MonitorAdmin class

copyright(c) Tae Young Soft. All right reserved. 2014
*/
#include "stdafx.h"
#include "Taurus_Common/MonitorAdmin.h"

#include "Taurus_Viewer/IViewerProperty.h"
#include "Taurus_Xml/XmlFunc.h"

#define COMPILE_MULTIMON_STUBS
#include "Taurus_Common/Monitor.h"

#define MONITOR_PROPERTY_NAME  _T("monitor_property")

CMonitorAdmin* CMonitorAdmin::m_pInstace = NULL;

CMonitorAdmin::CMonitorAdmin()
  : m_pInitWorklistMonitor(NULL)
{}

CMonitorAdmin::~CMonitorAdmin()
{
  removeAllMonitors();
}

BOOL CMonitorAdmin::init()
{
  HDC hDC = ::GetDC(NULL);

  BOOL fOk = EnumDisplayMonitors(hDC,
                                 NULL,
                                 monitorEnumProc,
                                 (LPARAM)this);
  fOk = m_listMonitors.size() > 0;
  ::ReleaseDC(NULL, hDC);
  return fOk;
}

DWORD CMonitorAdmin::doConfigure(IViewerProperty* pProperties)
{
  unsigned nNumMonitors = m_listMonitors.size();

  //get monitor property node by using xpath
  CString strXPath;
  strXPath.Format(_T("//%s/%s"), VIEWER_PROPERTY_NAME, MONITOR_PROPERTY_NAME);
  MSXML2::IXMLDOMNodePtr pMonitorProp = pProperties->getProperty(strXPath);

  //flag indicating whether monitor properties must be updated or not 
  BOOL bMusteUpdateProp = FALSE;

  //if monitor property node is not exist in viewer property
  //then create new property by using current environment
  if(pMonitorProp == NULL)
  {
    MSXML2::IXMLDOMDocument2Ptr pNewMPropDoc = XmlFunc::CreateXmlDoc(
      MONITOR_PROPERTY_NAME, NULL, NULL);
    pMonitorProp = XmlFunc::GetRoot(pNewMPropDoc);
   
    //create monitor type node
    MSXML2::IXMLDOMNodePtr pMonitorType = XmlFunc::CreateNewChild(
      pMonitorProp, _T("monitor_type"));
    XmlFunc::SetAttributeInt(
      pMonitorType, _T("count"), (int)nNumMonitors, NULL, NULL);

    for(unsigned i = 0; i < nNumMonitors; i++)
    {
      MSXML2::IXMLDOMNodePtr pMonitorNode = XmlFunc::CreateNewChild(
        pMonitorType, _T("monitor"));
      XmlFunc::SetAttributeBoolean(pMonitorNode, _T("visible"), TRUE, NULL, NULL);

      BOOL bShowWorklist = (i == 0 ? TRUE : FALSE);
      XmlFunc::SetAttributeBoolean(pMonitorNode,
                                   _T("show_worklist"),
                                   bShowWorklist,
                                   NULL,
                                   NULL);
    }

    bMusteUpdateProp = TRUE;
  }

  strXPath.Format(_T("./monitor_type[@count='%u']"), nNumMonitors);
  MSXML2::IXMLDOMNodePtr pMonitorTypeNode = XmlFunc::SelectSingleNodeInXmlNode(
    pMonitorProp, strXPath);
  if(pMonitorTypeNode == NULL)
  {
    pMonitorTypeNode = XmlFunc::CreateNewChild(pMonitorProp, _T("monitor_type"));
    XmlFunc::SetAttributeInt(
      pMonitorTypeNode, _T("count"), static_cast<int>(nNumMonitors), NULL, NULL);

    for(unsigned i = 0; i < nNumMonitors; ++i)
    {
      MSXML2::IXMLDOMNodePtr pMonitorNode = XmlFunc::CreateNewChild(
        pMonitorTypeNode, _T("monitor"));

      XmlFunc::SetAttributeBoolean(pMonitorNode, _T("visible"), TRUE, NULL, NULL);

      BOOL bShowWorklist = (i == 0 ? TRUE : FALSE);
      XmlFunc::SetAttributeBoolean(
        pMonitorNode, _T("show_worklist"), bShowWorklist, NULL, NULL);
    }

    bMusteUpdateProp = TRUE;
  }

  clearProperty();

  MSXML2::IXMLDOMNodeListPtr pMonitorNodeList = XmlFunc::GetChildren(pMonitorTypeNode);
  long nNumMonitorNodes = pMonitorNodeList->Getlength();
  for(long nNodeIndex = 0; nNodeIndex < nNumMonitorNodes; ++nNodeIndex)
  {
    MSXML2::IXMLDOMNodePtr pMonitorNode = pMonitorNodeList->Getitem(nNodeIndex);
    if(pMonitorNode == NULL)
      continue;

    auto monitorPos = m_listMonitors.begin();
    std::advance(monitorPos, nNodeIndex);
    CMonitor* pMonitor = (*monitorPos);

    BOOL bVisibleWorklist = FALSE;
    XmlFunc::GetAttributeBoolean(pMonitorNode, _T("show_worklist"), bVisibleWorklist);
    if(bVisibleWorklist)
      m_pInitWorklistMonitor = pMonitor;

    BOOL bVisibleMonitor = FALSE;
    XmlFunc::GetAttributeBoolean(pMonitorNode, _T("visible"), bVisibleMonitor);
    if(bVisibleMonitor)
      m_listVisibleMonitors.push_back(pMonitor);
    else
      m_listHiddenMonitors.push_back(pMonitor);
  }

  MSXML2::IXMLDOMNodePtr pMisc = XmlFunc::SelectSingleNodeInXmlNode(
    pMonitorProp, _T("monitor_misc"));
  if(pMisc)
  {
    BOOL bShowTaskbar = FALSE;
    XmlFunc::GetAttributeBoolean(pMisc, _T("show_taskbar"), bShowTaskbar);
    if(!bShowTaskbar)
    {
      for_each(m_listMonitors.begin(), m_listMonitors.end(),
        [](CMonitor* pMonitor)
      {
        const RECT* prcRect = pMonitor->getRect();
        pMonitor->setWorkRect(*prcRect);
      });
    }
  }

  if(bMusteUpdateProp)
    pProperties->updateProperty(VIEWER_PROPERTY_NAME,
                                MONITOR_PROPERTY_NAME,
                                pMonitorProp);

  buildMonitorLayoutString();

  return ERROR_SUCCESS;
}

CMonitorAdmin* CMonitorAdmin::getInstance()
{
  if(m_pInstace == NULL)
    _TRY_ALLOC(m_pInstace, CMonitorAdmin)

    return m_pInstace;
}

DWORD CMonitorAdmin::addMonitor(CMonitor* pMonitor)
{
  if(pMonitor == NULL)
    return ERROR_INVALID_PARAMETER;

  BOOL bInserted = FALSE;
  const RECT* prcNewMonitor = pMonitor->getRect();
  for(auto i = m_listMonitors.begin(), e = m_listMonitors.end(); i!=e; ++i)
  {
    if((*i) == NULL)
      continue;

    const RECT* prcMonitor = (*i)->getRect();
    if(prcMonitor->left > prcNewMonitor->left)
    {
      _TRY_BEGIN
      m_listMonitors.insert(i, pMonitor);
      _CATCH_ALL
      return ERROR_NOT_ENOUGH_MEMORY;
      _CATCH_END

      bInserted = TRUE;
      break;
    }
  }

  if(!bInserted)
  {
    _TRY_BEGIN
    m_listMonitors.push_back(pMonitor);
    _CATCH_ALL
    return ERROR_NOT_ENOUGH_MEMORY;
    _CATCH_END
  }
  return ERROR_SUCCESS;
}

void CMonitorAdmin::removeAllMonitors()
{
  for(auto i = m_listMonitors.begin(), e = m_listMonitors.end(); i != e; ++i)
    _DELETE((*i));
  m_listMonitors.clear();
  clearProperty();
}

BOOL CMonitorAdmin::monitorEnumProc(HMONITOR hMonitor, 
                                    HDC hDC, 
                                    LPRECT lpRect, 
                                    LPARAM lParam)
{
  CMonitorAdmin* pMA = reinterpret_cast<CMonitorAdmin*>(lParam);

  MONITORINFOEX stMonitorInfoEX;
  stMonitorInfoEX.cbSize = sizeof(stMonitorInfoEX);
  BOOL fOk = ::GetMonitorInfo(hMonitor, &stMonitorInfoEX);
  if(!fOk)
    return FALSE;

  DEVMODE stDevMode;
  stDevMode.dmSize = sizeof(stDevMode);
  EnumDisplaySettings(stMonitorInfoEX.szDevice, ENUM_CURRENT_SETTINGS, &stDevMode);

  DWORD dwError = ERROR_SUCCESS;
  if(stDevMode.dmDisplayFrequency != 0)
  {
    MonitorResolutionType enumResType =  MonitorResolution_Normal;
    int iRatio = ::GetDeviceCaps(hDC, HORZRES) * ::GetDeviceCaps(hDC, VERTRES);
    if(iRatio < 1536 * 2048)
      enumResType = MonitorResolution_Normal;
    else if(iRatio < 2048 * 2560)
      enumResType = MonitorResolution_3M;
    else
      enumResType = MonitorResolution_5M;
  
    CMonitor* pNewMonitor = NULL;
    _TRY_ALLOC(pNewMonitor, CMonitor);
    if(pNewMonitor == NULL)
    {
      pMA->removeAllMonitors();
      return FALSE;
    }

    dwError = pNewMonitor->init(hMonitor, stMonitorInfoEX, stDevMode, enumResType);
    if(dwError != ERROR_SUCCESS)
    {
      _DELETE(pNewMonitor);
      pMA->removeAllMonitors();
      return FALSE;
    }

    dwError = pMA->addMonitor(pNewMonitor);
    if(dwError != ERROR_SUCCESS)
    {
      _DELETE(pNewMonitor);
      pMA->removeAllMonitors();
      return FALSE;
    }
  }

  return TRUE;
}

const CMonitor* CMonitorAdmin::getVisibleMonitor(unsigned nIndex) const
{
  if(nIndex >= m_listVisibleMonitors.size())
    return NULL;

  auto res = m_listVisibleMonitors.cbegin();
  std::advance(res, nIndex);
  return (*res);
}

const CMonitor* CMonitorAdmin::getHiddenMonitor(unsigned nIndex) const
{

  if(nIndex >= m_listHiddenMonitors.size())
    return NULL;

  auto res = m_listHiddenMonitors.cbegin();
  std::advance(res, nIndex);
  return (*res);
}

const TCHAR* CMonitorAdmin::getMonitorLayoutString(unsigned index) const
{
  if(index >= m_arrMonitorLayoutString.size()) return nullptr;

  return m_arrMonitorLayoutString[index];
}

DWORD CMonitorAdmin::buildMonitorLayoutString()
{
  m_arrMonitorLayoutString.clear();

  unsigned nNumVisibleMonitors = m_listVisibleMonitors.size();

  try
  {
    switch(nNumVisibleMonitors)
    {
    case 1:
      {
        m_arrMonitorLayoutString.reserve(1);
        m_arrMonitorLayoutString.push_back(_T("1"));
      }
      break;
    case 2:
      {
        m_arrMonitorLayoutString.reserve(2);
        m_arrMonitorLayoutString.push_back(_T("1-1"));
        m_arrMonitorLayoutString.push_back(_T("2"));
      }
      break;
    case 3:
      {
        m_arrMonitorLayoutString.reserve(4);
        m_arrMonitorLayoutString.push_back(_T("1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-2"));
        m_arrMonitorLayoutString.push_back(_T("2-1"));
        m_arrMonitorLayoutString.push_back(_T("3"));
      }
      break;
    case 4:
      {
        m_arrMonitorLayoutString.reserve(8);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-2-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-3"));
        m_arrMonitorLayoutString.push_back(_T("3-1"));
        m_arrMonitorLayoutString.push_back(_T("2-2"));
        m_arrMonitorLayoutString.push_back(_T("4"));
      }
      break;
    case 5:
      {
        m_arrMonitorLayoutString.reserve(14);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-1-2-1"));
        m_arrMonitorLayoutString.push_back(_T("1-2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-3"));
        m_arrMonitorLayoutString.push_back(_T("1-3-1"));
        m_arrMonitorLayoutString.push_back(_T("3-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-2-2"));
        m_arrMonitorLayoutString.push_back(_T("2-2-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-4"));
        m_arrMonitorLayoutString.push_back(_T("4-1"));
        m_arrMonitorLayoutString.push_back(_T("5"));
      }
      break;
    case 6:
      {
        m_arrMonitorLayoutString.reserve(16);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-2-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-2-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-3"));
        m_arrMonitorLayoutString.push_back(_T("1-1-3-1"));
        m_arrMonitorLayoutString.push_back(_T("1-3-1-1"));
        m_arrMonitorLayoutString.push_back(_T("3-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-4"));
        m_arrMonitorLayoutString.push_back(_T("1-4-1"));
        m_arrMonitorLayoutString.push_back(_T("4-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-5"));
        m_arrMonitorLayoutString.push_back(_T("5-1"));
        m_arrMonitorLayoutString.push_back(_T("6"));
      }
      break;
    case 7:
      {
        m_arrMonitorLayoutString.reserve(22);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-1")); 
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-2-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-2-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-2-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-1-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-3"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-3-1"));   
        m_arrMonitorLayoutString.push_back(_T("1-1-3-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-3-1-1-1"));   
        m_arrMonitorLayoutString.push_back(_T("3-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-4"));	 
        m_arrMonitorLayoutString.push_back(_T("1-1-4-1"));
        m_arrMonitorLayoutString.push_back(_T("1-4-1-1"));    
        m_arrMonitorLayoutString.push_back(_T("4-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-5"));	 
        m_arrMonitorLayoutString.push_back(_T("1-5-1"));
        m_arrMonitorLayoutString.push_back(_T("5-1-1"));	 
        m_arrMonitorLayoutString.push_back(_T("1-6"));
        m_arrMonitorLayoutString.push_back(_T("6-1"));	     
        m_arrMonitorLayoutString.push_back(_T("7"));
      }
      break; 
    case 8:
      {
        m_arrMonitorLayoutString.reserve(29);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-1-1")); 
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-2-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-2-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-2-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-2-1-1-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("2-1-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-3"));   
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-3-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-3-1-1"));   
        m_arrMonitorLayoutString.push_back(_T("1-1-3-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-3-1-1-1-1"));   
        m_arrMonitorLayoutString.push_back(_T("3-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-4"));	  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-4-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-4-1-1"));    
        m_arrMonitorLayoutString.push_back(_T("1-4-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("4-1-1-1-1"));	  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-5"));
        m_arrMonitorLayoutString.push_back(_T("1-1-5-1"));	  
        m_arrMonitorLayoutString.push_back(_T("1-5-1-1"));
        m_arrMonitorLayoutString.push_back(_T("5-1-1-1"));	  
        m_arrMonitorLayoutString.push_back(_T("1-1-6"));
        m_arrMonitorLayoutString.push_back(_T("1-6-1"));  	  
        m_arrMonitorLayoutString.push_back(_T("6-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-7"));		  
        m_arrMonitorLayoutString.push_back(_T("7-1"));
        m_arrMonitorLayoutString.push_back(_T("8"));
      }
      break; 
    case 9:
      {
        m_arrMonitorLayoutString.reserve(37);
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-1-1-1")); 
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-1-2"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-2-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-2-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-2-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-2-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-2-1-1-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-2-1-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("2-1-1-1-1-1-1-1"));  
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-1-3"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-3-1"));   
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-3-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-3-1-1-1"));   
        m_arrMonitorLayoutString.push_back(_T("1-1-3-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-3-1-1-1-1-1"));   
        m_arrMonitorLayoutString.push_back(_T("3-1-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-1-4"));	   
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-4-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-4-1-1"));    
        m_arrMonitorLayoutString.push_back(_T("1-1-4-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-4-1-1-1-1"));	   
        m_arrMonitorLayoutString.push_back(_T("4-1-1-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-1-1-5"));	   
        m_arrMonitorLayoutString.push_back(_T("1-1-1-5-1"));
        m_arrMonitorLayoutString.push_back(_T("1-1-5-1-1"));     
        m_arrMonitorLayoutString.push_back(_T("1-5-1-1-1"));
        m_arrMonitorLayoutString.push_back(_T("5-1-1-1-1"));	   
        m_arrMonitorLayoutString.push_back(_T("1-1-1-6"));
        m_arrMonitorLayoutString.push_back(_T("1-1-6-1"));  	   
        m_arrMonitorLayoutString.push_back(_T("1-6-1-1"));
        m_arrMonitorLayoutString.push_back(_T("6-1-1-1"));	   
        m_arrMonitorLayoutString.push_back(_T("1-1-7"));
        m_arrMonitorLayoutString.push_back(_T("1-7-1"));	   
        m_arrMonitorLayoutString.push_back(_T("7-1-1"));
        m_arrMonitorLayoutString.push_back(_T("1-8"));		   
        m_arrMonitorLayoutString.push_back(_T("8-1"));
        m_arrMonitorLayoutString.push_back(_T("9"));  
      }
      break;
    case 10:
      {
        m_arrMonitorLayoutString.reserve(46);
        m_arrMonitorLayoutString.push_back(_T("1111111111")); 
        m_arrMonitorLayoutString.push_back(_T("111111112"));
        m_arrMonitorLayoutString.push_back(_T("111111121"));  
        m_arrMonitorLayoutString.push_back(_T("111111211"));
        m_arrMonitorLayoutString.push_back(_T("111112111"));  
        m_arrMonitorLayoutString.push_back(_T("111121111"));
        m_arrMonitorLayoutString.push_back(_T("111211111"));  
        m_arrMonitorLayoutString.push_back(_T("112111111"));
        m_arrMonitorLayoutString.push_back(_T("121111111"));  
        m_arrMonitorLayoutString.push_back(_T("211111111"));
        m_arrMonitorLayoutString.push_back(_T("11111113"));	
        m_arrMonitorLayoutString.push_back(_T("11111131"));
        m_arrMonitorLayoutString.push_back(_T("11111311"));   
        m_arrMonitorLayoutString.push_back(_T("11113111"));
        m_arrMonitorLayoutString.push_back(_T("11131111"));   
        m_arrMonitorLayoutString.push_back(_T("11311111"));
        m_arrMonitorLayoutString.push_back(_T("13111111"));   
        m_arrMonitorLayoutString.push_back(_T("31111111"));
        m_arrMonitorLayoutString.push_back(_T("1111114"));	
        m_arrMonitorLayoutString.push_back(_T("1111141"));
        m_arrMonitorLayoutString.push_back(_T("1111411"));    
        m_arrMonitorLayoutString.push_back(_T("1114111"));
        m_arrMonitorLayoutString.push_back(_T("1141111"));	
        m_arrMonitorLayoutString.push_back(_T("1411111"));
        m_arrMonitorLayoutString.push_back(_T("4111111"));	
        m_arrMonitorLayoutString.push_back(_T("111115"));
        m_arrMonitorLayoutString.push_back(_T("111151"));	    
        m_arrMonitorLayoutString.push_back(_T("111511"));
        m_arrMonitorLayoutString.push_back(_T("115111"));     
        m_arrMonitorLayoutString.push_back(_T("151111"));
        m_arrMonitorLayoutString.push_back(_T("511111"));	    
        m_arrMonitorLayoutString.push_back(_T("11116"));
        m_arrMonitorLayoutString.push_back(_T("11161")); 	    
        m_arrMonitorLayoutString.push_back(_T("11611"));
        m_arrMonitorLayoutString.push_back(_T("16111"));	    
        m_arrMonitorLayoutString.push_back(_T("61111"));
        m_arrMonitorLayoutString.push_back(_T("1117"));		
        m_arrMonitorLayoutString.push_back(_T("1171"));
        m_arrMonitorLayoutString.push_back(_T("1711")); 	    
        m_arrMonitorLayoutString.push_back(_T("7111"));
        m_arrMonitorLayoutString.push_back(_T("118"));		
        m_arrMonitorLayoutString.push_back(_T("181"));
        m_arrMonitorLayoutString.push_back(_T("811"));		
        m_arrMonitorLayoutString.push_back(_T("19"));
        m_arrMonitorLayoutString.push_back(_T("91"));		    
        m_arrMonitorLayoutString.push_back(_T("10"));
      }
      break;
    }
  }
  catch(const std::bad_alloc&)
  {
    m_arrMonitorLayoutString.clear();
    return ERROR_NOT_ENOUGH_MEMORY;
  }

  return ERROR_SUCCESS;
}

void CMonitorAdmin::clearProperty()
{
  m_arrMonitorLayoutString.clear();
  m_pInitWorklistMonitor = NULL;
  m_listVisibleMonitors.clear();
  m_listHiddenMonitors.clear();
}